@extends('admin.layouts.base')

@section('content')
    <div class="row wrapper border-bottom white-bg page-heading">
        <div class="col-sm-4">
            <h2>用户管理</h2>
            {!! Breadcrumbs::render(Route::currentRouteName()) !!}
        </div>
        @if(Auth::guard('admin')->user()->can('admin.user.create'))
        <div class="col-sm-8">
            <div class="title-action">
                <a href="{{url('admin/user/create')}}" class="btn btn-primary"><i class="fa fa-plus-circle"></i> 添加用户</a>
            </div>
        </div>
        @endif
    </div>
    <div class="wrapper wrapper-content">
        <div class="row">
            <div class="col-lg-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>后台用户列表</h5>
                    </div>
                    @include('admin.partials.success')
                    @include('admin.partials.errors')
                    <div class="ibox-content">
                        <table class="footable table table-stripped toggle-arrow-tiny tablet breakpoint footable-loaded" data-page-size="8">
                            <thead>
                            <tr>
                                <th data-toggle="true" class="footable-visible footable-first-column footable-sortable">ID<span class="footable-sort-indicator"></span></th>
                                <th class="footable-visible footable-sortable">账号<span class="footable-sort-indicator"></span></th>
                                <th class="footable-visible footable-sortable">上次登录时间<span class="footable-sort-indicator"></span></th>
                                <th class="footable-visible footable-sortable">上次登录IP<span class="footable-sort-indicator"></span></th>
                                <th class="footable-visible footable-sortable">登录次数<span class="footable-sort-indicator"></span></th>
                                <th class="footable-visible footable-sortable">注册时间<span class="footable-sort-indicator"></span></th>
                                <th class="footable-visible footable-last-column footable-sortable">激活状态<span class="footable-sort-indicator"></span></th>
                                <th class="footable-visible footable-last-column footable-sortable">操作<span class="footable-sort-indicator"></span></th>
                            </tr>
                            </thead>
                            <tbody>
                            @foreach($admins as $admin)
                            <tr style="display: table-row;" class="footable-even">
                                <td class="footable-visible footable-first-column"><span class="footable-toggle"></span>{{$admin->id}}</td>
                                <td class="footable-visible">{{$admin->account_number}}</td>
                                <td class="footable-visible">{{date('Y-m-d H:i',$admin->last_login_time)}}</td>
                                <td class="footable-visible">{{long2ip($admin->last_login_ip)}}</td>
                                <td class="footable-visible">{{$admin->login_count}}</td>
                                <td class="footable-visible">{{date('Y-m-d H:i',$admin->create_time)}}</td>
                                <td class="footable-visible footable-last-column"><a href="#"><i class="fa fa-check text-navy"></i></a></td>
                                <td class="footable-visible footable-last-column">
                                    @if(Auth::guard('admin')->user()->can('admin.user.edit'))
                                        <a href="/admin/user/{{$admin->id}}/edit" class="X-Small btn-xs text-success "><i class="fa fa-edit"></i> 编辑</a>|
                                    @endif
                                    @if(Auth::guard('admin')->user()->can('admin.user.destroy'))
                                        @if($admin->id != 1)
                                            <a href="javascript:void(0);" data-value="{{$admin->id}}" class="X-Small btn-xs text-success delete"><i class="fa fa-trash"></i> 删除</a>
                                        @else
                                            <a href="javascript:void(0);" class="X-Small btn-xs text-success"><i class="fa fa-ban"></i> 禁删</a>
                                        @endif
                                    @endif
                                </td>
                            </tr>
                            @endforeach
                            </tbody>
                            <tfoot>
                                <tr><td colspan="8" class="footable-visible">{!! $admins->links() !!}</td></tr>
                            </tfoot>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="modal fade" id="modal-delete" tabIndex="-1">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">
                        ×
                    </button>
                    <h4 class="modal-title">提示</h4>
                </div>
                <div class="modal-body">
                    <p class="lead">
                        <i class="fa fa-question-circle fa-lg"></i>
                        确认要删除这个用户吗?
                    </p>
                </div>
                <div class="modal-footer">
                    <form class="deleteForm" method="POST" action="{{url('admin/user')}}">
                        <input type="hidden" name="_token" value="{{ csrf_token() }}">
                        <input type="hidden" name="_method" value="DELETE">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button type="submit" class="btn btn-danger">
                            <i class="fa fa-times-circle"></i>确认
                        </button>
                    </form>
                </div>
            </div>
        </div>
    </div>
@stop
@section('js')
    <script type="text/javascript">
        $('a.delete').bind('click',function () {
            var id = $(this).attr('data-value');
            $('.deleteForm').attr('action','/admin/user/' + id);
            $("#modal-delete").modal();
        })
    </script>
@endsection
